﻿/*
 * @Author: huang yuanfa
 * @Date: 2022-11-17 10:01:14
 * @LastEditTime: 2022-12-11 11:55:11
 * @LastEditors: huang yuanfa
 * Copyright 2022 huang yuanfa All Rights Reserved.
 * @Gitee: https://gitee.com/huangyuanfa
 * @Github: https://github.com/hyf888
 * @FilePath: /HThreadPool/src/Utils/ThreadPool/ThreadPool.inl
 * @Description: file content
 */

#ifndef THREADPOOL_INL
#define THREADPOOL_INL

#include "ThreadPool.h"

HTHREADPOOL_NAMESPACE_BEGIN

    template<int DefaultStrategy, typename F, typename... Args>
    auto ThreadPool::commit(F && f, Args && ... args)->std::future<decltype(f(args...))>
    {
        using RetType = decltype(f(args...));
        std::packaged_task<RetType()> task(std::bind(std::forward<F>(f), std::forward<Args>(args)...));
        std::future<RetType>          result(task.get_future());
        m_taskQueue.push(std::move(task));

        return result;
    }

    template<typename Func>
    auto ThreadPool::commitWithPriority(const Func& func, int priority)
        ->std::future<typename std::result_of<Func()>::type>
    {
        using ResultType = typename std::result_of<Func()>::type;

        std::packaged_task<ResultType()> task(func);
        std::future<ResultType>          result(task.get_future());

        //    if (m_secondary_threads.empty())
        //    {
        //        createSecondaryThread(1); // 如果没有开启辅助线程，则直接开启一个
        //    }

        //    m_priority_task_queue.push(std::move(task), priority);
        //    m_inputTaskNum++;
        return result;
    }

HTHREADPOOL_NAMESPACE_END

#endif
